//
//  CRMTextField.m
//  CordovaLib
//
//  Created by decade on 14/12/2017.
//

#import "CRMTextField.h"

@interface CRMTextField()

@end

@implementation CRMTextField

- (id)initWithFrame:(CGRect)frame placeHolder:(NSString *)placeHolder secureText:(BOOL)secureText clearsOnBegin:(BOOL)clearsOnBegin imageNamed:(NSString *)imageNamed customKeyboard:(UIKeyboardType)customKeyboard {
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *leftimage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageNamed]];
        leftimage.frame = CGRectMake(0, 0, 35, 35);
        
        leftimage.contentMode = UIViewContentModeBottom;
        self.leftView = leftimage;
        self.leftViewMode = UITextFieldViewModeAlways;
        self.backgroundColor = [UIColor clearColor];
        self.font = [UIFont systemFontOfSize:16];
        self.textColor = [UIColor blackColor];
        self.clearButtonMode = UITextFieldViewModeWhileEditing;
        self.secureTextEntry = secureText;
        self.clearsOnBeginEditing = clearsOnBegin;
        self.autocorrectionType = UITextAutocorrectionTypeNo;
        self.textAlignment = NSTextAlignmentLeft;
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        self.keyboardType = customKeyboard;
        self.autocapitalizationType = UITextAutocapitalizationTypeNone;
        self.returnKeyType = UIReturnKeyDone;
        self.placeholder = placeHolder;
        NSMutableAttributedString *placeholderAttributed = [[NSMutableAttributedString alloc] initWithString:placeHolder];
        [placeholderAttributed addAttribute:NSForegroundColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, placeHolder.length)];
        [placeholderAttributed addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:16] range:NSMakeRange(0, placeHolder.length)];
        self.attributedPlaceholder = placeholderAttributed;
        UIView *bottomLine = [[UIView alloc]initWithFrame:CGRectMake(0, 56, mycontentViewWidth, 1)];
        bottomLine.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:bottomLine];
    }
    return self;
}

- (CGRect)textRectForBounds:(CGRect)bounds {
    CGRect textRect = [super textRectForBounds:bounds];
    textRect.origin.y += 10;
    return textRect;
}

- (CGRect)editingRectForBounds:(CGRect)bounds {
    CGRect textRect = [super textRectForBounds:bounds];
    textRect.origin.y += 10;
    return textRect;
}

@end
